package com.platform.dao.mybatis;

import com.platform.dao.DictDao;
import com.platform.dao.mybatis.mapper.TbSysCodeClassMapper;
import com.platform.dao.mybatis.mapper.TbSysCodeMapper;
import com.platform.domain.TbSysCode;
import com.platform.domain.TbSysCodeClass;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: wangyanginfo
 * Date: 12-8-20
 * Time: 下午6:20
 * To change this template use File | Settings | File Templates.
 */
@Service("dictDao")
public class DictDaoImpl implements DictDao {

    @Resource
    private TbSysCodeClassMapper tbSysCodeClassMapper;

    @Resource
    private TbSysCodeMapper tbSysCodeMapper;


    /**
     * 根据主键查询字典分类
     *
     * @param classId 分类ID
     * @return 字典分类对象
     * @throws Exception
     */
    @Override
    public TbSysCodeClass queryCodeClass(String classId) throws Exception {
        return tbSysCodeClassMapper.selectByPrimaryKey(classId);
    }

    /**
     * 根据字典分类对象条件查询符合条件的字典分类对象集合
     *
     * @param codeClass 字典分类对象
     * @return 字典对象集合
     * @throws Exception
     */
    @Override
    public List<TbSysCodeClass> queryCodeClass(TbSysCodeClass codeClass) throws Exception {
        return tbSysCodeClassMapper.select(codeClass);
    }

    /**
     * 插入新的字典分类
     *
     * @param codeClass 字典分类对象
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int insertCodeClass(TbSysCodeClass codeClass) throws Exception {
        return tbSysCodeClassMapper.insertSelective(codeClass);
    }

    /**
     * 更新字典分类
     *
     * @param codeClass 字典分类对象
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int updateCodeClass(TbSysCodeClass codeClass) throws Exception {
        return tbSysCodeClassMapper.updateByPrimaryKeySelective(codeClass);
    }

    /**
     * 根据主键删除字典分类
     *
     * @param classId 分类ID
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int deleteCodeClass(String classId) throws Exception {
        return tbSysCodeClassMapper.deleteByPrimaryKey(classId);
    }

    /**
     * 根据主键查询字典
     *
     * @param codeId 分类ID
     * @return 字典对象
     * @throws Exception
     */
    @Override
    public TbSysCode queryCode(String codeId) throws Exception {
        return tbSysCodeMapper.selectByPrimaryKey(codeId);
    }

    /**
     * 根据字典对象条件查询符合条件的字典对象集合
     *
     * @param code 字典对象
     * @return 字典对象集合
     * @throws Exception
     */
    @Override
    public List<TbSysCode> queryCodes(TbSysCode code) throws Exception {
        return tbSysCodeMapper.select(code);
    }

    /**
     * 插入新的字典对象
     *
     * @param code 字典对象
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int insertCode(TbSysCode code) throws Exception {
        return tbSysCodeMapper.insertSelective(code);
    }

    /**
     * 更新字典
     *
     * @param code 字典对象
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int updateCode(TbSysCode code) throws Exception {
        return tbSysCodeMapper.updateByPrimaryKeySelective(code);
    }

    /**
     * 根据主键删除字典
     *
     * @param codeId 字典ID
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int deleteCode(String codeId) throws Exception {
        return tbSysCodeMapper.deleteByPrimaryKey(codeId);
    }
}
